home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / dial / d_master.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-03-23  |  5.2 KB  |  209 lines

  1. # include  "util.h"
  2. # include  "d_proto.h"
  3. # include  "d_returns.h"
  4. # include  <signal.h>
  5. # include  "d_syscodes.h"
  6. # include  "d_clogcodes.h"
  7. # include  "ll_log.h"
  8.  
  9. /*
  10.  *     D_MASCONN
  11.  *
  12.  *     this routine is called by the master protocl module to initiate a
  13.  *     connection to a remote system.  the scriptfile used contains all
  14.  *     of the information necessary to dial the remote machine, set
  15.  *     parameters.
  16.  *
  17.  *     scriptfile -- name of the script file
  18.  *
  19.  *     logfile -- name of the file to be used for logging.  if this arg
  20.  *                is 0, then logging is done on the standard output
  21.  *
  22.  *     tson -- this argument should be non-zero if the protocol module
  23.  *             should keep a transcript of the connection
  24.  *
  25.  *     tsfile -- name of the file in which the transcript should be kept.
  26.  *
  27.  *     debug -- set to non-zero to enable more extensive logging
  28.  *
  29.  */
  30.  
  31. d_masconn(scriptfile, logfile, tson, tsfile, debug)
  32.   char  *scriptfile, *tsfile;
  33.   struct ll_struct * logfile;
  34.   int  tson, debug;
  35.     {
  36.     extern int  d_debug, d_master, d_snseq, d_rcvseq;
  37.     register int  result;
  38.  
  39.     /*  open the log and transcript file  */
  40.     d_debug = debug;
  41.  
  42.     if ((result = d_opnlog(logfile)) < 0)
  43.       return(result);
  44.  
  45.     d_init();
  46.  
  47.     if (tson)
  48.       if ((result = d_tsopen(tsfile)) < 0)
  49.         return(result);
  50.  
  51.     d_master = 1;
  52.     /* numbers will be incremented before use, thus effectively start at 0 */
  53.     d_snseq = 3;
  54.     d_rcvseq = 3;
  55.  
  56.     /*  open the script file and start interpreting it  */
  57.     if ((result = d_scopen(scriptfile, 0, (char **) 0)) < 0)
  58.       return(result);
  59.  
  60.     if ((result = d_script()) < 0)
  61.       return(result);
  62.  
  63.     /*  when the script file pauses, start the protocol  */
  64.     result = d_masstart();
  65.     return(result);
  66. }
  67.  
  68. /*
  69.  *     D_MASDROP
  70.  *
  71.  *     this routine is called by the master to drop the connection to the
  72.  *     other side.  the port, lock, transcript, and log files are closed.
  73.  *
  74.  *     sndquit -- non-zero if a QUIT sequence should be initiated with
  75.  *                the other side
  76.  *
  77.  *     doscript -- non-zero if the script should be resumed
  78.  */
  79.  
  80. d_masdrop(sndquit, doscript)
  81.   register int  sndquit, doscript;
  82.     {
  83.     register int  result;
  84.  
  85.     d_dbglog("d_masdrop", "dropping connection, sndquit %d, doscript %d",
  86.         sndquit, doscript);
  87.  
  88.     result = 0;
  89.  
  90.     /*  go through the QUIT sequence if we're supposed to  */
  91.     if (sndquit)
  92.       d_snquit();
  93.  
  94.     /*  resume the script, if enabled  */
  95.     if (doscript)
  96.       {
  97. #ifdef D_LOG
  98.       d_log("d_masdrop", "Resuming script file.");
  99. #endif D_LOG
  100.       result = d_script();
  101.       }
  102.  
  103. #ifdef D_LOG
  104.     d_log("d_masdrop", "master dropped connection");
  105. #endif D_LOG
  106.  
  107.     /*  drop the connection.  close the transcript and log  */
  108.     d_drop();
  109.     d_tsclose();
  110.     d_clslog();
  111.  
  112.     return(result);
  113. }
  114.  
  115. /*
  116.  *     D_MASSTART
  117.  *
  118.  *     this routine is called in the master to start up the protocol once
  119.  *     the matching slave routine has been started.  this function exchanges
  120.  *     RESET's with the slave and sets up the escape characters for the
  121.  *     encoding.
  122.  */
  123.  
  124. d_masstart()
  125.     {
  126.     extern int  d_lxmax, d_lrmax, d_rxmax, d_rrmax, d_maxtext, d_nbuff;
  127.     extern int d_wpack;
  128.     extern int d_errno;
  129.     extern char  d_snesc, d_rcvesc;
  130.     extern unsigned short  d_lxill[], d_lrill[], d_rxill[], d_rrill[],
  131.     d_lcvec[];
  132.     register int  result;
  133.  
  134. #ifdef D_DBGLOG
  135.     d_dbglog("d_masstart", "Beginning master host startup sequence");
  136. #endif D_DBGLOG
  137.  
  138.     /*  get the XPATH and RPATH packets from the slave. then build
  139.      *  the local transmit code vector.
  140.      */
  141.     if ((result = d_getpath(XPATH, &d_rxmax, d_rxill)) < 0)
  142.       return(result);
  143.  
  144. #ifdef D_DBGLOG
  145.     d_dbglog("d_masstart", "XPATH received ok.");
  146. #endif D_DBGLOG
  147.  
  148.     if ((result = d_getpath(RPATH, &d_rrmax, d_rrill)) < 0)
  149.       return(result);
  150.  
  151. #ifdef D_DBGLOG
  152.     d_dbglog("d_masstart", "RPATH received ok.");
  153. #endif D_DBGLOG
  154.  
  155.     /*  If appropriate, send the packet describing how we are buffering
  156.      *  packets.  This cannot be sent to some sites, as they do not
  157.      *  recognize the packet type.
  158.      */
  159.     if (d_wpack != 0)
  160.     d_setbuff (d_nbuff);
  161.  
  162.     d_orbitvec(d_lxill, d_rrill, d_lcvec);
  163.  
  164.     d_maxtext = d_minimum(d_lxmax, d_rrmax);
  165. #ifdef D_DBGLOG
  166.     d_dbglog("d_masstart", "Maximum transmit packet size set to %d", d_maxtext);
  167. #endif D_DBGLOG
  168.     d_maxtext -= (LHEADER + LTERM);
  169.  
  170.     /*  now send the XPATH and RPATH to the slave  */
  171.     if ((result = d_snpath(XPATH, d_lxmax, d_lxill)) < 0)
  172.       return(result);
  173.  
  174. #ifdef D_DBGLOG
  175.     d_dbglog("d_masstart", "XPATH sent ok.");
  176. #endif D_DBGLOG
  177.  
  178.     if ((result = d_snpath(RPATH, d_lrmax, d_lrill)) < 0)
  179.       return(result);
  180.  
  181. #ifdef D_DBGLOG
  182.     d_dbglog("d_masstart", "RPATH sent ok.");
  183. #endif D_DBGLOG
  184.  
  185.     /*  get the escape code we're to use for encoding text sent
  186.      *  to the remote host.
  187.      */
  188.     if ((result = d_getescape()) < 0)
  189.       return(result);
  190.  
  191. #ifdef D_DBGLOG
  192.     d_dbglog("d_masstart", "ESCAPE received ok.  Transmit escape '%c'",
  193.     d_snesc);
  194. #endif D_DBGLOG
  195.  
  196.     if ((result = d_snfescape()) < 0)
  197.       return(result);
  198.  
  199. #ifdef D_DBGLOG
  200.     d_dbglog("d_masstart", "ESCAPE sent ok.  Receive escape '%c'", d_rcvesc);
  201. #endif D_DBGLOG
  202.  
  203. #ifdef D_LOG
  204.     d_log("d_masstart", "Master protocol startup completed ok.");
  205. #endif D_LOG
  206.  
  207.     return(D_OK);
  208. }
  209.